<?php
/*
 * @Author: your name
 * @Date: 2020-12-23 12:01:16
 * @LastEditTime: 2020-12-28 10:25:04
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /special/application/common/service/module_manage/hgshield/NormalRuleGroup.php
 */

namespace app\common\service;


use think\Db;

class NormalRuleGroup
{
    /**
     * @name 列表
     * @param $hostId
     * @param $params
     * @return array
     * @author wx
     * @date 2019/11/12 10:58
     */
    public function list($hostId, $params)
    {
        $server = Db::name('normal_rule_group')->alias('nrg')
            ->field('nrg.id, nrg.name, nrg.description, hnrgr.status, hnrgr.total, hnrgr.used')
            ->join('host_normal_rule_group_relation hnrgr', 'hnrgr.group_id = nrg.id')
            ->where('host_id', $hostId);

        !isset($params['name']) || empty($params['name']) ? : $server->whereLike('name', '%'. $params['name'] . '%');
        !isset($params['description']) || empty($params['description']) ? : $server->whereLike('description', '%'. $params['description'] . '%');
        !isset($params['status']) || !is_numeric($params['status']) ? : $server->where('hnrgr.status', $params['status']);
        $data = $server->paginate()->toArray();

        return $data;
    }
}